package day6.HomeWork;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

//a.定义一个User类  属性: id  name  userinfo   和 UserInfo类 属性 id sex age
//   定义一个List存储10个User对象  数据可以 自行添加
//   通过迭代器的方式遍历出来集合的每个元素 中的id name sex age属性
public class A {
    public static void main(String[] args) {
        List<User> list = new ArrayList<>();
        Random r = new Random();
        for (int i = 0; i < 10; i++) {
            String name = String.valueOf(getName());
            String sex = r.nextInt(2) == 1 ? "男" : "女";
            Integer age = r.nextInt(100) + 1;
            list.add(new User(i + 1, name, new UserInfo(i + 1, sex, age)));
        }
        Iterator<User> it = list.iterator();
        while (it.hasNext()) {
            User u = it.next();
            System.out.println(u);
        }
    }

    public static StringBuilder getName() {
        Random r = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 4; i++) {
            sb.append((char) (r.nextInt(26) + 65));
        }
        return sb;
    }
}

class User {
    int id;
    String name;
    UserInfo userInfo;

    public User(int id, String name, UserInfo userInfo) {
        this.id = id;
        this.name = name;
        this.userInfo = userInfo;
    }

    @Override
    public String toString() {
        String str = id + "\t" + name + "\t" + userInfo.sex + "\t" + userInfo.age;
        return str;
    }
}

class UserInfo {
    int id;
    String sex;
    int age;

    public UserInfo(int id, String sex, int age) {
        this.id = id;
        this.sex = sex;
        this.age = age;
    }
}